#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project : python的学习
@File    : 列表、元组、字符串、字典、函数.py
@IDE     : PyCharm
@Author  : 春风十里
@Date    : 2023/6/13 14:41

'''
# 列表
l = [1, 2, 3]  # 下标/索引：0开始
print(l[1])
l = [1, 2, 3, 4, 5]
for i in l:
    print(i, end=" ")
l = [1, 2, 3, 4, 5]
l[2], l[3] = l[3], l[2]
print(l)

# 添加元素
l = [1, 2, 3, 4, 5]
l.extend([6, 7])
print(l)
# 删除元素
l = [1, 2, 3, 4, 5]
l.remove(4)
print(l)
# 修改元素
l = [1, 2, 3, 4, 5]
l[2] = 6
print(l)
# 切片的高级操作
l = [1, 2, 3, 4, 5]
print(l[0:4])
# 列表的进阶操作
l = [1, 2, 3, 4, 5]
n = l[-1:-3:-1]
print(n)
l = [1, 2, 3, 4, 5, 6]
l2 = [2, 3, 4, 6]
print(l < l2)
l = [1, 2, 3, 4, 5, 6]
l2 = [1, 2, 3, 4, 5]
print(l + l2)
l = [2, 3, 4, 5, 6]
print(l * 2)
l = [1, 2, 3, 4, 5]
print(5 in l)
l = [1, 2, 3, 4, 5]
l.reverse()
print(l)
# 冒泡排序
l = [6, 5, 4, 3, 2, 1]
for i in range(1, len(l)):
    for j in range(len(l) - i):
        if l[j] > l[j + 1]:
            l[j], l[j + 1] = l[j + 1], l[j]
print(l)
# 选择排序
l = [9, 8, 7, 6, 5]
for i in range(0, len(l) - 1):
    for j in range(i + 1, len(l)):
        if l[i] > l[j]:
            l[i], l[j] = l[j], l[i]
print(l)
# 元组
t = (1, 2, 3, 4, 5)
print(t[2])
n = t[2:4]
print(n)
# 修改和删除
t = (1, 2, 3, 4, 5, 6)
l = list(t)
print(l)
l[2] = 6
print(l)
t = tuple(l)
print(t)
# 删除
t = (1, 2, 3, 4, 5, 6)
l = list(t)
print(l)
del l[2]
print(l)
t = tuple(l)
print(t)
# 字符串
a = "hello world"
b = a.capitalize()
print(b)
# 格式化字符串
"{0} 嘿嘿".format("python")
a = 100
s = "{0}{1}{2} 嘿嘿"
s2 = s.format(a, "JAVA", "C++")
print(s2)
# 字典
d3 = dict([("one", 1), ("two", 2)])
print(d3)
d4 = dict(a=3, b=4)
print(d4)
d = {"name": "小黑"}
print(d["name"])


# 函数的使用
def fun2(a, n):
    print(a * n)


# 打印古诗
print("白日依山尽")
fun2("+", 5)
print("黄河入海流")
fun2("+", 10)
print("欲穷千里目")
fun2("+", 15)
print("更上一层楼")
fun2("/", 20)
